const StashService = require("../service/stash.service")

class StashController {
    async create(ctx,next) {
        const { name,chargeId,address,area,phone,capacity,remark } = ctx.request.body
        try {
            const result = await StashService.create(name,chargeId,address,area,phone,capacity,remark)
            ctx.body = result
        } catch (error) {
            console.log('error',error);
        }
    }
    async list(ctx,next) {
        const page = ctx.query.page || 1
        const pageSize = ctx.query.pageSize || 10
        const { totalCount } = await StashService.getListCount()
        const offset = (page - 1) * pageSize
        const items = await StashService.getList(pageSize,offset)
        
        ctx.body = {
            totalCount,
            items
        }
    }
    async edit(ctx,next) {
        const { id,name,phone,address,chargeId,area,capacity,remark } = ctx.request.body
        const result = await StashService.edit(id,name,phone,address,chargeId,area,capacity,remark)
        ctx.body = result
    }
    async remove(ctx,next) {
        const { id } = ctx.query
        const result = await StashService.remove(id)
        ctx.body = result
    }
}

module.exports = new StashController()